﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
using MahApps.Metro;

namespace ProjTemp.Desktop.Common.Controls
{
    /// <summary>
    /// Interaction logic for CustomMetroWindow.xaml
    /// </summary>
    public class CustomMetroUserControl : UserControl
    {
        //protected Theme currentTheme = Theme.Light;
        //protected Accent currentAccent = ThemeManager.DefaultAccents.First(x => x.Name == "Green");

        public CustomMetroUserControl()
        {
            this.Initialize();
        }

        protected void Initialize()
        {
            this.LoadResourceDictionary();
        }

        private void LoadResourceDictionary()
        {
            var resourceDictionary = new ResourceDictionary();
            resourceDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml") });
            resourceDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.TextBlock.xaml") });
            resourceDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml") });
            resourceDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/ProjTemp.Desktop.Common;component/Themes/BusyIndicator.xaml") });
            resourceDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/MahApps.Metro.Resources;component/Icons.xaml") });

            this.Resources = resourceDictionary;
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var TextBlockStyle = this.FindResource(StyleConst.MetroTextBlockKey);
            if (TextBlockStyle != null && !this.Resources.Contains(typeof(TextBlock)))
                this.Resources.Add(typeof(TextBlock), TextBlockStyle);
        }
    }
}